merge?
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 7 Sep 2005 21:34:17 +0000 (21:34 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 7 Sep 2005 21:34:17 +0000 (21:34 +0000)
1  2 
tools/xenstore/xenstored_domain.c

index 1798b11c09b23c0d1c779acf32dc8a1fa32700bd,3f50257a3229b6964abea1fb067bafd4be15976c..cd347bc3d96ac2d254c6f5725279f2e31037e23b
@@@ -1,4 -1,4 +1,4 @@@
--/* 
++/*
      Domain communications for Xen Store Daemon.
      Copyright (C) 2005 Rusty Russell IBM Corporation
  
@@@ -407,7 -407,7 +407,7 @@@ void do_get_domain_path(struct connecti
        else
                domain = find_domain_by_domid(domid);
  
--      if (!domain) 
++      if (!domain)
                send_error(conn, ENOENT);
        else
                send_reply(conn, XS_GET_DOMAIN_PATH, domain->path,
@@@ -436,30 -440,50 +440,48 @@@ void restore_existing_connections(void
  /* Returns the event channel handle. */
  int domain_init(void)
  {
 -    /* The size of the ringbuffer: half a page minus head structure. */
 -    ringbuf_datasize = getpagesize() / 2 - sizeof(struct ringbuf_head);
 -    
 -    xc_handle = talloc(talloc_autofree_context(), int);
 -    if (!xc_handle)
 -        barf_perror("Failed to allocate domain handle");
 -
 -    *xc_handle = xc_interface_open();
 -    if (*xc_handle < 0)
 -        barf_perror("Failed to open connection to hypervisor (privcmd)");
 -
 -    talloc_set_destructor(xc_handle, close_xc_handle);
 -    
++      struct stat st;
++
 +      /* The size of the ringbuffer: half a page minus head structure. */
 +      ringbuf_datasize = getpagesize() / 2 - sizeof(struct ringbuf_head);
 +
 +      xc_handle = talloc(talloc_autofree_context(), int);
 +      if (!xc_handle)
 +              barf_perror("Failed to allocate domain handle");
++
 +      *xc_handle = xc_interface_open();
 +      if (*xc_handle < 0)
 +              barf_perror("Failed to open connection to hypervisor");
++
 +      talloc_set_destructor(xc_handle, close_xc_handle);
 +
  #ifdef TESTING
 -    eventchn_fd = fake_open_eventchn();
 +      eventchn_fd = fake_open_eventchn();
  #else
-       eventchn_fd = open("/dev/xen/evtchn", O_RDWR);
 -    {
 -        struct stat st;
 -        
 -        /* Make sure any existing device file links to correct device. */
 -        if ( (lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
 -             (st.st_rdev != makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)) )
 -            (void)unlink(EVTCHN_DEV_NAME);
 -        
 -      reopen:
 -        eventchn_fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
 -        if (eventchn_fd == -1) {
 -            if ((errno == ENOENT) && (
 -                    (mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) 
 -                && (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600,
 -                          makedev(EVTCHN_DEV_MAJOR,EVTCHN_DEV_MINOR)) == 0))
 -                goto reopen;
 -            return -errno;
 -        }
 -    }
++      /* Make sure any existing device file links to correct device. */
++      if ((lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
++          (st.st_rdev != makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)))
++              (void)unlink(EVTCHN_DEV_NAME);
++
++ reopen:
++      eventchn_fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
++      if (eventchn_fd == -1) {
++              if ((errno == ENOENT) &&
++                  ((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
++                  (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600,
++                         makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)) == 0))
++                      goto reopen;
++              return -errno;
++      }
  #endif
 -    if (eventchn_fd < 0)
 -        barf_perror("Failed to open connection to hypervisor (evtchn)");
 -    
 -    if (xc_evtchn_bind_virq(*xc_handle, VIRQ_DOM_EXC, &virq_port))
 -        barf_perror("Failed to bind to domain exception virq");
 -    
 -    if (ioctl(eventchn_fd, EVENTCHN_BIND, virq_port) != 0)
 -        barf_perror("Failed to bind to domain exception virq port");
 -    
 -    return eventchn_fd;
 +      if (eventchn_fd < 0)
-               barf_perror("Failed to open connection to hypervisor");
++              barf_perror("Failed to open connection evtchn device");
 +
 +      if (xc_evtchn_bind_virq(*xc_handle, VIRQ_DOM_EXC, &virq_port))
 +              barf_perror("Failed to bind to domain exception virq");
 +
 +      if (ioctl(eventchn_fd, EVENTCHN_BIND, virq_port) != 0)
 +              barf_perror("Failed to bind to domain exception virq port");
 +
 +      return eventchn_fd;
  }